package com.ssm.controller;

import com.ssm.dao.SysMenuDao;
import com.ssm.entity.SysMenuEntity;
import com.ssm.entity.UserVo;
import com.ssm.service.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;
    @Autowired
    private SysMenuDao sysMenuDao;

    @RequestMapping("/showUser.do")
    public void selectUser(HttpServletRequest request, HttpServletResponse response) throws IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        long userId = Long.parseLong(request.getParameter("id"));
        UserVo user = this.userService.selectUser(userId);
//        ObjectMapper mapper = new ObjectMapper();
  //      response.getWriter().write(mapper.writeValueAsString(user));
        response.getWriter().close();
    }

    @Controller
    public class LoginController {
        @RequestMapping("/login")
        public String login() {
            return "sys/login";
        }
    }

    @RequestMapping("/a")
    @RequiresPermissions("sys:role:select")
    public void index(){
        System.out.println("asd");
    }

    @RequestMapping("/getUserAll")
    public
    Map<String, Object> getUserAll(){
        Map<String,Object> map = new HashMap<>();
        List<SysMenuEntity> strings = sysMenuDao.queryList(new HashMap<String, Object>());
        map.put("persm", strings);
        return map;
    }
}
